package leecode.array.容器盛水问题;

/**
 * https://leetcode.cn/problems/container-with-most-water/
 */
public class MaxArea {
    public int maxArea(int[] height) {
        // 双指针 , 并不是贪心
        if (height == null || height.length <= 0) {
            return 0;
        }
        int i = 0;
        int j = height.length - 1;
        int result = (j - i) * Math.min(height[i], height[j]);
        while (i < j) {
            if (height[i] <= height[j]) {
                i++;
            } else {
                j--;
            }
            int temp = (j - i) * Math.min(height[i], height[j]);
            result = Math.max(temp, result);
        }
        return result;
    }
}
